<template>
  <div class="header">
    <div class="header-left">
      <div @click="$router.push({
        name: 'home'
      })" class="left-img" style="margin-right: 100px;">
        <img src="/img/logo.png" alt="">
      </div>
      <div @click="$router.push('/home')">首页</div>
      <div @click="$router.push('/shop')">商城</div>
      <div>关于我们</div>
      <div>博客</div>
    </div>
    <div class="header-right">
      <div @click.stop>
        <img v-show="store.inputToSearch2" @click="() => {
          store.inputToSearchToTrue()
          store.inputToSearch2ToFalse()
        }" src="/img/search.png" alt="">

        <transition enter-active-class="animate__animated animate__rubberBand" leave-active-class="animate__animated animate__zoomOutUp">
          <div v-show="store.inputToSearch" class="right-search">
            <input maxlength="40" type="text">
            <img src="/img/search.png" alt="">
          </div>
        </transition>
      </div>
      <div>
        <img src="/img/love.png" alt="">
      </div>
      <div style="margin-right: 40px;">
        <!-- 购物车按钮 -->
        <el-badge @click="cartCard = true" badge-style="background-color: #088395;font-size: 11px;font-family: Roboto;" :value="2" class="item">
          <img src="/img/cart.png" alt="">
        </el-badge>
      </div>
      <div>
        <div v-if="!bool" class="login-button" @click="$router.push({
          name: 'login'
        })">
          登录
        </div>
        <div v-else class="avatar">
          <img @click="$router.push({
            name: 'profile_my'
          })" src="/img/avatar.jpg" alt="">
        </div>
      </div>
    </div>
    <!-- 购物车抽屉 -->
    <el-drawer v-model="cartCard" :show-close="false" size="25%" direction="rtl">
      <template #header>
        <div class="header-card">您的购物车中有<span class="header-card-num"> 两件 </span>商品！</div>
      </template>
      <div class="cart-order-i">
        <!-- 商品1 -->
        <div class="cart-order-card">
          <div class="cart-order-card-left">
            <div class="cart-order-card-left-img">
              <img src="/img/g7small.png" alt="">
            </div>
            <div class="cart-order-card-left-content">
              <div class="cart-order-card-left-content-name">巴洛克华冠</div>
              <div class="cart-order-card-left-content-price">￥599.00</div>
              <div class="cart-order-card-left-content-num">数量：1</div>
            </div>
          </div>
          <div class="cart-order-card-right">
            <el-icon style="cursor: pointer;" @click="removeCardItem(1)" :size="18" color="rgb(255, 114, 98)">
              <Delete />
            </el-icon>
          </div>
        </div>
        <!-- 商品2 -->
        <div class="cart-order-card">
          <div class="cart-order-card-left">
            <div class="cart-order-card-left-img">
              <img src="/img/g7small.png" alt="">
            </div>
            <div class="cart-order-card-left-content">
              <div class="cart-order-card-left-content-name">巴洛克华冠</div>
              <div class="cart-order-card-left-content-price">￥599.00</div>
              <div class="cart-order-card-left-content-num">数量：1</div>
            </div>
          </div>
          <div class="cart-order-card-right">
            <el-icon style="cursor: pointer;" @click="removeCardItem(1)" :size="18" color="rgb(255, 114, 98)">
              <Delete />
            </el-icon>
          </div>
        </div>
      </div>
      <div class="cart-order-card-bottom">
        <!-- 总计 -->
        <div class="cart-order-card-total">
          <div class="card-total-left">总计</div>
          <div class="card-total-right">￥1024.00</div>
        </div>
        <!-- 结账按钮 -->
        <div class="cart-order-card-checkout" @click="$router.push({
          name: 'checkout'
        })">去付款</div>
      </div>
    </el-drawer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useInputStore } from '@/state/inputState'

const store = useInputStore()

// 头像是否展示
const bool = ref(true)

// 购物车抽屉状态
const cartCard = ref(false)

const removeCardItem = (id: number) => {
  // 传过来的id是购物车中的id，根据id删除即可
  console.log(`这里是购物车的id: ${ id }`)
}
</script>

<style lang="less" scoped>
.header {
  margin: auto;
  width: 70%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .header-left {
    display: flex;
    height: 100%;
    align-items: center;

    > div:not(:first-child) {
      margin-right: 30px;
      cursor: pointer;
    }

    .left-img {
      width: 58px;
      height: 53px;
      cursor: pointer;
    }
  }

  .header-right {
    display: flex;
    height: 100%;
    align-items: center;

    > div:not(:last-child) {
      margin-right: 30px;
      cursor: pointer;

      img {
        width: 22px;
        height: 22px;
      }
    }

    .right-search {
      position: relative;
      width: auto;
      height: 36px;

      input {
        width: 300px;
        height: 36px;
        border-radius: 18px;
        box-sizing: border-box;
        outline: none;
        padding: 0 15px 0 35px;
        font-family: 'Helvetica';
        font-size: 14px;
      }

      img {
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translate(0, -50%);
      }
    }

    > div:last-child {
      img {
        width: 48px;
        height: 48px;
        border-radius: 50%;
      }
    }

    .login-button {
      width: 115px;
      height: 50px;
      background-color: #088395;
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;

      color: rgb(255, 255, 255);
      font-family: Epilogue;
      font-size: 16px;
      font-weight: 400;
      line-height: 30px;

      transition: background 0.4s;
      cursor: pointer;
    }

    .login-button:hover {
      background: rgb(22, 162, 184);
    }

    .avatar {
      cursor: pointer;
    }
  }

  .header-card {
    color: rgb(20, 28, 29);
    font-family: 'Helvetica';
    font-size: 16px;
    font-weight: 400;
    line-height: 30px;
    letter-spacing: 0%;
    text-align: left;

    .header-card-num {
      font-weight: bold;
    }
  }

  .cart-order-i {
    height: 725px;
    overflow: auto;

    .cart-order-card {
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid rgba(163, 170, 171, 0.2);
      padding-bottom: 20px;

      .cart-order-card-left {
        display: flex;

        .cart-order-card-left-img {
          width: 70px;
          height: 70px;
          box-sizing: border-box;
          border: 0.59px solid rgba(163, 170, 171, 0.2);
          border-radius: 5px;
          display: flex;
          align-items: center;
          justify-content: center;

          img {
            width: 50px;
            height: 50px;
          }
        }

        .cart-order-card-left-content {
          margin-left: 10px;
          height: 100%;
          display: flex;
          flex-direction: column;
          justify-content: space-between;

          .cart-order-card-left-content-name {
            color: rgb(20, 28, 29);
            font-family: Epilogue;
            font-size: 14px;
            font-weight: 400;
          }

          .cart-order-card-left-content-price {
            color: rgb(20, 28, 29);
            font-family: Epilogue;
            font-size: 14px;
            font-weight: 700;
          }

          .cart-order-card-left-content-num {
            color: rgb(20, 28, 29);
            font-family: Epilogue;
            font-size: 14px;
            font-weight: 400;
          }
        }
      }

      .cart-order-card-right {
        height: 70px;
        display: flex;
        align-items: end;
      }
    }

    .cart-order-card:not(:last-child) {
      margin-bottom: 20px;
    }
  }

  .cart-order-card-bottom {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translate(-50%, 0);
    width: 92%;

    .cart-order-card-total {
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;

      color: rgb(20, 28, 29);
      font-family: Epilogue;
      font-size: 16px;
      font-weight: 700;

      .card-total-left {
        margin-left: 2px;
      }

      .card-total-right {
        margin-right: 4px;
      }
    }

    .cart-order-card-checkout {
      width: 100%;
      height: 50px;
      border-radius: 10px;
      background: rgb(8, 131, 149);

      display: flex;
      align-items: center;
      justify-content: center;

      color: rgb(255, 255, 255);
      font-family: Epilogue;
      font-size: 16px;
      font-weight: 400;
      cursor: pointer;

      transition: background 0.4s;
    }

    .cart-order-card-checkout:hover {
      background: rgb(22, 162, 184);
    }
  }
}
</style>